<?php

namespace app\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule =   [
        'username'  => 'require|max:25',
        'captcha'   => "require",
        'password'  => 'require|chsAlphaNum|max:12|min:6',
        'user_id'   => "require|number",
        'age'   => 'number|between:1,120',
        'email' => 'email',
    ];


    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message  =   [
        'username.require' => '用户名必须',
        'username.max'     => '名称最多不能超过25个字符',
        'captcha.require' => '验证码必须',
        'user_id.require' => '用户标示必须',
        'user_id.number'     => '用户标示是数字类型',
        'password.require' => '密码必须',
        'password.max'     => '密码最多不能超过12个字符',
        'password.min'     => '密码最少不能少于6个字符',
        'age.number'   => '年龄必须是数字',
        'age.between'  => '年龄只能在1-120之间',
        'email'        => '邮箱格式错误',
    ];

    protected $scene = [
        'edit'  =>  ['username','password','user_id'],
        'create'  =>  ['username','password','captcha'],
        'read'  =>  ['user_id'],
    ];
}
